import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_base_plugin/flutter_base_plugin.dart';
import 'package:flutter_base_plugin_example/page/details/goods/vm/goods_details_view_model.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

import '../../../config/k_color.dart';
import '../../../models/goods_details_model.dart';

/// @author:  JoeKai
/// @date 2022/6/27 19:39
/// @explain：

// ignore: camel_case_types, must_be_immutable
class GoodsDetailsWebView extends BaseStateless<GoodsDetailsViewModel> {
  late StoreInfo storeInfo;

  // InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
  //     crossPlatform: InAppWebViewOptions(
  //       useShouldOverrideUrlLoading: true,
  //       mediaPlaybackRequiresUserGesture: false,
  //     ),
  //     android: AndroidInAppWebViewOptions(
  //       useHybridComposition: true,
  //     ),
  //     ios: IOSInAppWebViewOptions(
  //       allowsInlineMediaPlayback: true,
  //     ));

  @override
  Widget buildWidget(BuildContext context) {
    storeInfo = viewModel.data!.storeInfo!;

    // TODO: implement buildWidget
    return Expanded(
      child: InAppWebView(
        onWebViewCreated: (controller) {
          controller.loadData(data: storeInfo.description!);
        },
        onLoadStop: (controller, uri) {
          controller.getContentHeight().then((value) {
            print("Height:  " + value.toString());
            context
                .read<GoodsDetailsViewModel>()
                .setWebViewHeight(double.parse(value.toString()));
          });
        },
      ),
    );
  }
}
